#include "FontRender2D.h"

FontRender2D * FontRender2D::instance = NULL;

FontRender2D::FontRender2D(void)
{
	D3DXFONT_DESC fontDesc = {
								24,
								0,
								400,
								0,
								false,
								DEFAULT_CHARSET,
								OUT_TT_PRECIS,
								CLIP_DEFAULT_PRECIS,
								DEFAULT_PITCH,
								L"Arial"
							  };

	D3DXCreateFontIndirect(CDirectXEngine::Instance()->d3ddev, &fontDesc, &dxFont);

	fontPosition.top = 0;
	fontPosition.left = 0;
	fontPosition.right = 800;
	fontPosition.bottom = 600;

}

FontRender2D * FontRender2D::Instance()
{
	if( instance == NULL)
		instance = new FontRender2D();

	return instance;
}

FontRender2D::~FontRender2D(void)
{
}

void FontRender2D::DrawText(int x, int y, std::wstring text)
{	
	DrawText(x, y, DT_LEFT, text);
}

void FontRender2D::DrawText(int x, int y, int alignment, std::wstring text)
{
	DrawText(x, y, alignment, text, 0xffffffff);
}


void FontRender2D::DrawText(int x, int y, int alignment, std::wstring text, unsigned int colour)
{
	fontPosition.top = y; //FIXME: dont think this is right
	fontPosition.left = x;

	dxFont->DrawText(NULL,
				   (LPCWSTR)text.c_str(),
				   -1,
				   &fontPosition,
				   alignment,
				   colour); //draw text
}

void FontRender2D::SetFontPos(int x, int y)
{
	fontPosition.top = x; //FIXME: dont think this is right
	fontPosition.left = y;
}
